package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ApArticleConfigServiceImpl
        extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig>
        implements ApArticleConfigService {
    /**
     * 修改文章配置
     *
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
        if (map != null) {
            Object articleId = map.get("articleId");
            Object enable = map.get("enable");
            ApArticleConfig articleConfig = getOne(Wrappers.<ApArticleConfig>lambdaQuery()
                    .eq(ApArticleConfig::getArticleId, articleId));
            if (articleConfig != null && enable != null) {
                articleConfig.setIsDown(enable.equals(0));
                updateById(articleConfig);
            }
        }
    }
}
